package ru.aptu.gsp_banking.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import ru.aptu.gsp_banking.service.CurrencyService;
import ru.aptu.gsp_banking.snmp.Sender;

import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: alex
 * Date: 11/16/11
 * Time: 4:54 PM
 */

@Controller
public class MainController {

    @Autowired
    private CurrencyService currencyService;

    private boolean posted = false;

    @RequestMapping("/index")
    public String index() {
        return "redirect:/accounts";
    }

    @RequestMapping("/")
    public String home() {
        return "redirect:/index";
    }

    @RequestMapping("/team")
    public String team() {
        return "team";
    }

    @RequestMapping("/clients")
    public String clients() {
        return "clients";
    }

    @RequestMapping(value = "/rates", method = RequestMethod.POST)
    public String ratesPost() {
        posted = true;
        return "redirect:rates";
    }

    @RequestMapping(value = "/rates", method = RequestMethod.GET)
    public String ratesGet(Map<String, Object> map) {
        if (!posted) {
            return "redirect:logout";
        }
        posted = false;

        currencyService.updateCurrencyIfNeeded();
        map.put("currencyList", currencyService.listCurrency());
        return "rates";
    }

    @RequestMapping("/request_success")
    public String requestCompleted() {
        return "request_success";
    }

    @RequestMapping("/request_fail")
    public String requestFailed() {
        return "request_fail";
    }
}
